namespace Zj.OpenAuth.Repository.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class add_fluentapi_mapping_changes : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.Department",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Text = c.String(nullable: false, maxLength: 36),
                        Code = c.String(nullable: false, maxLength: 36),
                        Description = c.String(nullable: false, maxLength: 1000),
                        Phone = c.String(nullable: false),
                        Status = c.Int(nullable: false),
                        ManagerId = c.Int(),
                        CreatorId = c.Int(),
                        CreateTime = c.DateTime(nullable: false),
                        LastModifierId = c.Int(),
                        LastModifyTime = c.DateTime(),
                        ParentId = c.Int(),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Menu",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Text = c.String(nullable: false, maxLength: 36),
                        Code = c.String(nullable: false, maxLength: 36),
                        Level = c.Int(nullable: false),
                        Url = c.String(nullable: false, maxLength: 1000),
                        MenuType = c.Int(nullable: false),
                        Icon = c.String(nullable: false, maxLength: 1000),
                        Description = c.String(nullable: false, maxLength: 1000),
                        Status = c.Int(nullable: false),
                        Sort = c.Int(nullable: false),
                        CreatorId = c.Int(),
                        CreateTime = c.DateTime(nullable: false),
                        LastModifierId = c.Int(),
                        LastModifyTime = c.DateTime(),
                        ParentId = c.Int(),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Role",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Text = c.String(nullable: false, maxLength: 36),
                        Code = c.String(nullable: false, maxLength: 36),
                        Description = c.String(nullable: false, maxLength: 1000),
                        Status = c.Int(nullable: false),
                        CreatorId = c.Int(),
                        CreateTime = c.DateTime(nullable: false),
                        LastModifierId = c.Int(),
                        LastModifyTime = c.DateTime(),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.RoleMenuMappingMap",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        RoleId = c.Int(nullable: false),
                        MenuId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Menu", t => t.MenuId)
                .ForeignKey("dbo.Role", t => t.RoleId)
                .Index(t => t.RoleId)
                .Index(t => t.MenuId);
            
            CreateTable(
                "dbo.User",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Code = c.String(nullable: false, maxLength: 36),
                        Account = c.String(nullable: false, maxLength: 20),
                        RealName = c.String(nullable: false, maxLength: 20),
                        Password = c.String(nullable: false, maxLength: 64),
                        Phone = c.String(nullable: false, maxLength: 20),
                        Mobile = c.String(nullable: false, maxLength: 20),
                        Address = c.String(nullable: false, maxLength: 50),
                        Email = c.String(nullable: false, maxLength: 100),
                        QQ = c.Long(nullable: false),
                        WeChat = c.String(nullable: false, maxLength: 50),
                        Sex = c.Int(nullable: false),
                        Status = c.Int(nullable: false),
                        DepartmentId = c.Int(),
                        CreatorId = c.Int(),
                        CreateTime = c.DateTime(nullable: false),
                        LastModifierId = c.Int(),
                        LastModifyTime = c.DateTime(),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.UserRoleMappingMap",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        UserId = c.Int(nullable: false),
                        RoleId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Role", t => t.RoleId)
                .ForeignKey("dbo.User", t => t.UserId)
                .Index(t => t.UserId)
                .Index(t => t.RoleId);
            
        }
        
        public override void Down()
        {
            DropForeignKey("dbo.UserRoleMappingMap", "UserId", "dbo.User");
            DropForeignKey("dbo.UserRoleMappingMap", "RoleId", "dbo.Role");
            DropForeignKey("dbo.RoleMenuMappingMap", "RoleId", "dbo.Role");
            DropForeignKey("dbo.RoleMenuMappingMap", "MenuId", "dbo.Menu");
            DropIndex("dbo.UserRoleMappingMap", new[] { "RoleId" });
            DropIndex("dbo.UserRoleMappingMap", new[] { "UserId" });
            DropIndex("dbo.RoleMenuMappingMap", new[] { "MenuId" });
            DropIndex("dbo.RoleMenuMappingMap", new[] { "RoleId" });
            DropTable("dbo.UserRoleMappingMap");
            DropTable("dbo.User");
            DropTable("dbo.RoleMenuMappingMap");
            DropTable("dbo.Role");
            DropTable("dbo.Menu");
            DropTable("dbo.Department");
        }
    }
}
